package com.aaa;

import android.graphics.Color;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.GridLayout;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

public class BActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_bactivity);
        String s = getIntent().getStringExtra("number");
        Log.d("aaaaaaaa", "onCreate: " + s);
        String[] numbers = s.split(", ");
        GridLayout gridLayout = findViewById(R.id.gridLayout);

        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        int screenWidth = displayMetrics.widthPixels;
        int itemWidth = screenWidth / 3;
        gridLayout.setColumnCount(3);

        for (int i = 0; i < numbers.length; i++) {
            TextView textView = new TextView(this);
            textView.setText(numbers[i]);
            textView.setTextColor(Color.WHITE);
            textView.setPadding(20, 20, 20, 20);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams();
            params.width = itemWidth;
            params.columnSpec = GridLayout.spec(i % 3);
            params.rowSpec = GridLayout.spec(i / 3);
            if (Integer.parseInt(numbers[i]) % 6 == 1) {
                textView.setBackgroundColor(Color.RED);
                params.height = itemWidth * 2;
            } else if (Integer.parseInt(numbers[i]) % 6 == 2) {
                textView.setBackgroundColor(Color.BLUE);
                params.height = (int) (itemWidth * 1.5);
            } else if (Integer.parseInt(numbers[i]) % 6 == 3) {
                textView.setBackgroundColor(Color.RED);
                params.height = itemWidth * 2;
            } else if (Integer.parseInt(numbers[i]) % 6 == 4) {
                textView.setBackgroundColor(Color.BLUE);
                params.height = (int) (itemWidth * 1.5);
            } else if (Integer.parseInt(numbers[i]) % 6 == 5) {
                textView.setBackgroundColor(Color.RED);
                params.height = itemWidth * 2;
                params.topMargin=-180;
            } else {
                textView.setBackgroundColor(Color.BLUE);
                params.height = (int) (itemWidth * 1.5);

            }
            textView.setLayoutParams(params);
            gridLayout.addView(textView);
        }
    }
}
